﻿using System;

namespace Sail.Caching
{
    /// <summary>
    /// 接口
    /// </summary>
    public interface IAcquireContext
    {
        /// <summary>
        /// Action
        /// </summary>
        Action<IVolatileToken> Monitor { get; }
    }

    /// <summary>
    /// IAcquireContext接口实现
    /// </summary>
    public class AcquireContext<TKey> : IAcquireContext
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="key">T</param>
        /// <param name="monitor">Action</param>
        public AcquireContext(TKey key, Action<IVolatileToken> monitor)
        {
            Key = key;
            Monitor = monitor;
        }

        /// <summary>
        /// T
        /// </summary>
        public TKey Key { get; private set; }

        /// <summary>
        /// Action
        /// </summary>
        public Action<IVolatileToken> Monitor { get; private set; }
    }

    /// <summary>
    /// IAcquireContext的lamdba实现
    /// </summary>
    public class SimpleAcquireContext : IAcquireContext
    {
        /// <summary>
        /// Action
        /// </summary>
        private readonly Action<IVolatileToken> _monitor;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="monitor"></param>
        public SimpleAcquireContext(Action<IVolatileToken> monitor)
        {
            _monitor = monitor;
        }

        /// <summary>
        /// Action
        /// </summary>
        public Action<IVolatileToken> Monitor
        {
            get { return _monitor; }
        }
    }
}
